﻿using System;
using System.Web;
using System.Web.Mvc;
using UncleBobWebService.Models;

namespace UncleBobApplicantWebService.Controllers
{
    public class SessionExpiredFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // Get the current HTTP context, and then retrieve the RegisterModel from the Session.
            HttpContext context = HttpContext.Current;
            RegisterModel currentRegistration = context.Session["User"] as RegisterModel;

            // If the RegisterModel does not exist, we know that the Session has timed out.
            if (currentRegistration == null)
            {
                filterContext.Result = new RedirectResult("~/Error/SessionTimeout");
                return;
            }

            base.OnActionExecuting(filterContext);
        }
    }
}